//
//  MallCommitOrdersViewController.m
//  CYWFrame
//
//  Created by Macx on 2017/9/2.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "MallCommitOrdersViewController.h"
#import "OrderGoods.h"
#import "MallAddressViewController.h"
#import "MallOrderGoodTableViewCell.h"
#import "MallHomeViewController.h"
#import "MallDetailViewController.h"
#import "MKJShoppingCartViewController.h"

#import "AliPayServer.h"
#import <Masonry.h>


@interface MallCommitOrdersViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) NSMutableArray *orderGoodArr;

@end

@implementation MallCommitOrdersViewController {
    UIView          *_shipAddressBgView;
    UIButton        *_addressImg;
    UIButton        *_goImg;
    UILabel         *_shipAddress;
    UILabel         *_shipAddrName;
    UILabel         *_shipAddrMobile;
    UIImageView     *_addreeBottomImg;
    UIView          *_shopOwnerBgView;
    UIImageView     *_shopOwnerImg;
    UILabel         *_shopOwnerName;
    UIView          *_shopBottomImg;

    
    UITableView     *_tableView;
    MallOrderGoodTableViewCell  *_cell;
    UIView          *_payWayBgView;
    UILabel         *_payWay;
    UIView          *_bottomBgView;
    UILabel         *_goodNum;
    UILabel         *_goodMoney;
    UIButton        *_payment;
    UIView          *_line;
    UIView          *_line2;
    UIButton        *_btn;       //支付宝支付
    UIButton        *_btn2;      //微信支付
    UIButton        *_cbtn;
    
    CGSize          _size1;
    CGSize          _size2;
    CGSize          _size3;
    
    
    NSMutableArray *summaryItems;
    NSMutableArray *shippingMethods;
    
}

- (void)viewWillAppear:(BOOL)animated {
	[self.navigationController setNavigationBarHidden:NO animated:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
	[self.navigationController setNavigationBarHidden:NO animated:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self createUI];
    
}


#pragma mark ==========构建UI==========
- (void)createUI {
    
//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"return"] style:UIBarButtonItemStylePlain target:self action:@selector(returnAction:)];
    
    
    self.navigationItem.title = @"提交订单";
    
    self.view.backgroundColor = UISeparatedColorRGB;
    
    _size1 = [LZCTools textSizeWithText:@"字数" font:kUHSystemFontWithSize(12)];
    _size2 = [LZCTools textSizeWithText:@"字数" font:kUHSystemFontWithSize(11)];
    _size3 = [LZCTools textSizeWithText:@"字数" font:kUHSystemFontWithSize(10)];
    
    _shipAddressBgView = [[UIView alloc] init];
    [self.view addSubview:_shipAddressBgView];
    _shipAddressBgView.backgroundColor = kWhiteColor;
    [_shipAddressBgView addTarget:self action:@selector(addressClick:)];
    
    _addressImg = [UIButton buttonWithType:UIButtonTypeCustom];
    [_shipAddressBgView addSubview:_addressImg];
    
    _goImg = [[UIButton alloc] init];
    [_shipAddressBgView addSubview:_goImg];
    [_goImg setImage:IMAGE(@"arrow_right_grey") forState:UIControlStateNormal];
    
    _shipAddrName = [[UILabel alloc] init];
    [_shipAddressBgView addSubview:_shipAddrName];
    _shipAddrName.textColor = kBlackColor;
    _shipAddrName.font = kUHSystemFontWithSize(12);
    
    _shipAddrMobile = [[UILabel alloc] init];
    [_shipAddressBgView addSubview:_shipAddrMobile];
    _shipAddrMobile.textColor = kGrayColor;
    _shipAddrMobile.font = kUHSystemFontWithSize(12);
    
    _addreeBottomImg = [[UIImageView alloc] init];
    _addreeBottomImg.image = IMAGE(@"address_border");
    [self.view addSubview:_addreeBottomImg];
    
    _shipAddress = [[UILabel alloc] init];
    [_shipAddressBgView addSubview:_shipAddress];
    _shipAddress.textColor = kGrayColor;
    _shipAddress.font = kUHSystemFontWithSize(12);
    
    
     if ([[NSString stringWithFormat:@"%@", [self.orderData[0] valueForKey:@"receive_addr"]] isEqualToString:@"<null>"]) {
        NSLog(@"没有地址");
        
        _shipAddrName.hidden = YES;
        _shipAddrMobile.hidden = YES;
        _addreeBottomImg.hidden = YES;
        
        _shipAddressBgView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SW(10)+10);
        
        _addressImg.frame = CGRectMake(10, 0, _size1.height, _size1.height);
        _addressImg.centerY = _shipAddressBgView.centerY;
        [_addressImg setImage:IMAGE(@"icon_add_address") forState:UIControlStateNormal];
        
        _goImg.frame = CGRectMake(SCREEN_WIDTH-10-_addressImg.width, _addressImg.y, _addressImg.width, _addressImg.width);
        
        _shipAddress.text = @"请添加收货地址";
        _shipAddress.frame = CGRectMake(_addressImg.x+_addressImg.width+5, 0, SCREEN_WIDTH-100, _shipAddressBgView.height);
        
    }
    else {
        NSLog(@"有地址");
        
        NSDictionary *addrDict = self.orderData[0];
        
        _shipAddrName.text = [[addrDict valueForKey:@"receive_addr"] valueForKey:@"name"];
        _shipAddrMobile.text = [[addrDict valueForKey:@"receive_addr"] valueForKey:@"mobile"];
        _shipAddress.text = [NSString stringWithFormat:@"%@%@%@%@", [[addrDict valueForKey:@"receive_addr"] valueForKey:@"province"], [[addrDict valueForKey:@"receive_addr"] valueForKey:@"city"], [[addrDict valueForKey:@"receive_addr"] valueForKey:@"district"], [[addrDict valueForKey:@"receive_addr"] valueForKey:@"detail"]];
        
        [self ownAddress];
        
    }
    
    int num = 0;
    float price = 0.0;
    float express_fee = 0.0;
    NSMutableArray *orderNumArr = [[NSMutableArray alloc] init];
    for (NSDictionary *odict in self.orderData) {
        NSArray *itemArr = odict[@"items"];
        [orderNumArr addObject:odict[@"order_id"]];
        num = (int)itemArr.count+num;
//        for (NSDictionary *itemDict in itemArr) {
//            price = [itemDict[@"price"] floatValue]*[itemDict[@"quantity"] integerValue]/100 + price;
//        }
        price = [odict[@"total_price"] floatValue]/100 + price;
        express_fee = [odict[@"express_fee"] floatValue]/100 + express_fee;
    }
    
    self.orderNum = [orderNumArr componentsJoinedByString:@","];
    
    CGFloat scrollY;
    if ([[NSString stringWithFormat:@"%@", [self.orderData[0] valueForKey:@"receive_addr"]] isEqualToString:@"<null>"]) {
        NSLog(@"没有地址");
        scrollY = _shipAddressBgView.y+_shipAddressBgView.height+10;
    }
    
    else {
        scrollY = _addreeBottomImg.y+_addreeBottomImg.height+10;
    }
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, scrollY, SCREEN_WIDTH, SCREEN_HEIGHT-scrollY-Height_NavBar-99) style:UITableViewStyleGrouped];
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor = UISeparatedColorRGB;
    
    //    设置分区高度 也可以使用代理方法
//    _tableView.sectionHeaderHeight = _size1.height+30;
//    _tableView.sectionFooterHeight = 80;
    _tableView.tableFooterView = [[UIView alloc]init];
    [_tableView registerNib:[UINib nibWithNibName:@"MallOrderGoodTableViewCell" bundle:nil] forCellReuseIdentifier:@"order"];
    
    [_tableView reloadData];
    
    // 底部
    _bottomBgView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-Height_NavBar-89, SCREEN_HEIGHT, 89)];
    [self.view addSubview:_bottomBgView];
	[_bottomBgView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerX.equalTo(self.view);
		make.width.equalTo(self.view);
		make.bottom.equalTo(self.view).offset(0);
		make.height.mas_equalTo(89);
	}];
    _bottomBgView.backgroundColor = kWhiteColor;
    
    _goodMoney = [[UILabel alloc] init];
    [_bottomBgView addSubview:_goodMoney];
    if (express_fee == 0.0) {
        _goodMoney.text = [NSString stringWithFormat:@"合计:%.2lf(免运费)", price];
    }
    else
        _goodMoney.text = [NSString stringWithFormat:@"合计:%.2lf(运费:%.2lf)", price, express_fee];
    
    _goodMoney.textColor = kGrayColor;
    _goodMoney.font = kUHSystemFontWithSize(12);
    CGSize moneyS = [LZCTools textSizeWithText:_goodMoney.text font:_goodMoney.font];
    _goodMoney.frame = CGRectMake(SCREEN_WIDTH-10-moneyS.width, 0, moneyS.width, 40);

    _goodNum = [[UILabel alloc] init];
    [_bottomBgView addSubview:_goodNum];
    _goodNum.text = [NSString stringWithFormat:@"共%d件商品", num];
    _goodNum.textColor = kGrayColor;
    _goodNum.font = kUHSystemFontWithSize(12);
    _goodNum.textAlignment = NSTextAlignmentRight;
    _goodNum.frame = CGRectMake(SCREEN_WIDTH-30-moneyS.width*2, 0, moneyS.width, 40);
	
	UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, _goodNum.y+_goodNum.height+1, SCREEN_WIDTH, 1)];
	line.backgroundColor = UISeparatedColorRGB;
	[_bottomBgView addSubview:line];
    //[self createLineFrame:CGRectMake(0, SCREEN_HEIGHT-Height_NavBar-49, SCREEN_WIDTH, 1)];
    
    _payment = [UIButton buttonWithType:UIButtonTypeCustom];
    [_bottomBgView addSubview:_payment];
    _payment.frame = CGRectMake(SW(3)*2, 40, SW(3), 49);
    _payment.backgroundColor = UIMainColorRGB;
    _payment.titleLabel.font = kUHSystemFontWithSize(12);
    [_payment setTitleColor:kWhiteColor forState:UIControlStateNormal];
    [_payment setTitle:@"确认付款" forState:UIControlStateNormal];
    _payment.tag = 201;
    [_payment addTarget:self action:@selector(paymentClick:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)ownAddress {
    
    _shipAddrName.hidden = NO;
    _shipAddrMobile.hidden = NO;
    _addreeBottomImg.hidden = NO;
    
    _shipAddressBgView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 3*SW(20)+10);
    
    _addressImg.frame = CGRectMake(10, 0, _size1.height, _size1.height);
    _addressImg.centerY = _shipAddressBgView.centerY;
    [_addressImg setImage:IMAGE(@"address_detail") forState:UIControlStateNormal];
    
    _goImg.frame = CGRectMake(SCREEN_WIDTH-10-_addressImg.width, _addressImg.y, _addressImg.width, _addressImg.width);
    
    
    CGSize nameS = [LZCTools textSizeWithText:_shipAddrName.text font:_shipAddrName.font];
    _shipAddrName.frame = CGRectMake(_addressImg.x+_addressImg.width+5, 0, nameS.width, nameS.height);
    _shipAddrName.y = _shipAddressBgView.centerY-3-nameS.height;
    
    _shipAddrMobile.frame = CGRectMake(_shipAddrName.x+_shipAddrName.width+5, _shipAddrName.y, SCREEN_WIDTH, nameS.height);
    
    _shipAddress.frame = CGRectMake(_addressImg.x+_addressImg.width+3, 0, SCREEN_WIDTH, nameS.height);
    _shipAddress.y = _shipAddressBgView.centerY+3;

    _addreeBottomImg.frame = CGRectMake(0, _shipAddressBgView.height, SCREEN_WIDTH, 5);
}

#pragma mark ==========UITableView==========
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    _cell = [tableView dequeueReusableCellWithIdentifier:@"order"];
    
    NSDictionary *dict = self.orderGoodArr[indexPath.section];
    OrderGoods *model = [[OrderGoods alloc] init];
    [model setValuesForKeysWithDictionary:((NSArray *)dict[@"items"])[indexPath.row]];
    //model = ((NSArray *)dict[@"items"])[indexPath.row];
    _cell.model = model;
    
    return _cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.orderGoodArr.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSDictionary *dict = self.orderGoodArr[section];
    return ((NSArray *)dict[@"items"]).count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 2*SW(9)+10;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSLog(@"点击tableView.cell = %ld", indexPath.row);
}
//   tableView代理方法 设置分区高度（可以根据不同分区设置不同高度等实现自定义）
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return _size1.height+30;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    if (section == self.orderData.count-1) {
        return 122;
    }
    else
        return 0;

}
//  自定义分区头的view
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    static NSString * identy =@"head";
    
    UITableViewHeaderFooterView * hf = [tableView dequeueReusableHeaderFooterViewWithIdentifier:identy];
    if (!hf) {
        hf = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:identy];
        
        _shopOwnerBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, _size1.height+30)];
        [hf addSubview:_shopOwnerBgView];
        _shopOwnerBgView.backgroundColor = kWhiteColor;
        
        _shopOwnerImg = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0, _addressImg.width, _addressImg.height)];
        [_shopOwnerBgView addSubview:_shopOwnerImg];
        _shopOwnerImg.image = IMAGE(@"placeHolder");
        NSString *imgStr = [[self.orderData[section] valueForKey:@"shop"] valueForKey:@"photo"];
        [_shopOwnerImg sd_setImageWithURL:[NSURL URLWithString:imgStr] placeholderImage:IMAGE(@"placeHolder")];
        
        _shopOwnerName = [[UILabel alloc] initWithFrame:CGRectMake(_shopOwnerImg.x+_shopOwnerImg.width+5, 0, SCREEN_WIDTH-100, _shopOwnerBgView.height)];
        [_shopOwnerBgView addSubview:_shopOwnerName];
        _shopOwnerName.textColor = kGrayColor;
        _shopOwnerName.font = kUHSystemFontWithSize(12);
        _shopOwnerName.text = [[self.orderData[section] valueForKey:@"shop"] valueForKey:@"shop_name"];
        
        _shopOwnerImg.centerY = _shopOwnerName.centerY;

    }
    return hf;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    if (section == self.orderGoodArr.count-1) {
        static NSString * identy = @"foot";
        UITableViewHeaderFooterView *ff = [tableView dequeueReusableHeaderFooterViewWithIdentifier:identy];
        // 最后一个分区才创建tableView
        if (!ff) {
            ff = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:identy];
            
            _payWayBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 122)];
            [ff addSubview:_payWayBgView];
            _payWayBgView.backgroundColor = kWhiteColor;
			_payWayBgView.userInteractionEnabled = YES;
            
            _payWay = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, SCREEN_WIDTH-40, 40)];
            [_payWayBgView addSubview:_payWay];
            _payWay.text = @"付款方式";
            _payWay.textColor = kGrayColor;
            _payWay.font = kUHSystemFontWithSize(12);
            
            _line = [[UIView alloc] initWithFrame:CGRectMake(0, _payWay.height, SCREEN_WIDTH, 1)];
            [_payWayBgView addSubview:_line];
            _line.backgroundColor = UISeparatedColorRGB;
			
			
			UIButton *alipayView = [[UIButton alloc] initWithFrame:CGRectMake(0, _line.y+2, SCREEN_WIDTH, 40)];
			[_payWayBgView addSubview:alipayView];
			UIButton *alipayBtn = [[UIButton alloc] initWithFrame:CGRectMake(20, 10, 85, 20)];
			[alipayBtn setTitle:@"支付宝" forState:UIControlStateNormal];
			[alipayBtn setTitleColor:kGrayColor forState:UIControlStateNormal];
			alipayBtn.titleLabel.font = kUHSystemFontWithSize(12);
			[alipayBtn setImage:IMAGE(@"pay_alipay") forState:UIControlStateNormal];
			alipayView.tag = 111;
			[alipayView addSubview:alipayBtn];
			[alipayView addTarget:self action:@selector(selectAliPayWay:)forControlEvents:UIControlEventTouchUpInside];
			
			
			_line2 = [[UIView alloc] initWithFrame:CGRectMake(0, alipayView.y+alipayView.height+1, SCREEN_WIDTH, 1)];
			_line2.backgroundColor = UISeparatedColorRGB;
			[_payWayBgView addSubview:_line2];
			
			UIButton *wechatView = [[UIButton alloc] initWithFrame:CGRectMake(0, _line2.y+2, SCREEN_WIDTH, 40)];
			[_payWayBgView addSubview:wechatView];
			UIButton *wechatPayBtn = [[UIButton alloc] initWithFrame:CGRectMake(20, 10, 100, 20)];
			[wechatPayBtn setTitle:@"微信支付" forState:UIControlStateNormal];
			wechatPayBtn.titleLabel.font = kUHSystemFontWithSize(12);
			[wechatPayBtn setTitleColor:kGrayColor forState:UIControlStateNormal];
			[wechatPayBtn setImage:IMAGE(@"pay_wechat") forState:UIControlStateNormal];
			wechatView.tag = 112;
			[wechatView addSubview:wechatPayBtn];
			[wechatView addTarget:self action:@selector(selectWechatPayWay:)forControlEvents:UIControlEventTouchUpInside];
			
			
			
			
			/*
			UIView *alipayView = [[UIView alloc] initWithFrame:CGRectMake(0, _payWay.height, SCREEN_WIDTH, 43)];
			[_payWayBgView addSubview:alipayView];
            _btn = [UIButton buttonWithType:UIButtonTypeCustom];
            [alipayView addSubview:_btn];
            _btn.titleLabel.font = kUHSystemFontWithSize(12);
            [_btn setTitle:@"支付宝支付" forState:UIControlStateNormal];
            [_btn setImage:IMAGE(@"pay_alipay") forState:UIControlStateNormal];
            [_btn setTitleColor:kGrayColor forState:UIControlStateNormal];
            _btn.tag = 111;
			[_btn addTarget:self action:@selector(selectAliPayWay:) forControlEvents:UIControlEventTouchUpInside];
             CGSize btnS = [LZCTools textSizeWithText:_btn.titleLabel.text font:_btn.titleLabel.font];
            _btn.frame = CGRectMake(20, 1, btnS.width+btnS.height+10, 40);
            
            _line2 = [[UIView alloc] initWithFrame:CGRectMake(0, alipayView.y+alipayView.height+1, SCREEN_WIDTH, 1)];
            [_payWayBgView addSubview:_line2];
            _line2.backgroundColor = UISeparatedColorRGB;
            NSLog(@"line2 y is %lf", _line2.y);
            
			//WechatView
			UIView *weChatView = [[UIView alloc] initWithFrame:CGRectMake(0, alipayView.y+alipayView.height+3, SCREEN_WIDTH, 43)];
			[_payWayBgView addSubview:weChatView];
            _btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
            [weChatView addSubview:_btn2];
            _btn2.titleLabel.font = kUHSystemFontWithSize(12);
            [_btn2 setTitle:@"微信支付" forState:UIControlStateNormal];
            [_btn2 setImage:IMAGE(@"pay_wechat") forState:UIControlStateNormal];
            [_btn2 setTitleColor:kGrayColor forState:UIControlStateNormal];
             _btn2.tag = 112;
			[_btn2 addTarget:self action:@selector(selectWechatPayWay:) forControlEvents:UIControlEventTouchUpInside];
			
            CGSize btnS2 = [LZCTools textSizeWithText:_btn2.titleLabel.text font:_btn2.titleLabel.font];
            _btn2.frame = CGRectMake(20, 1, btnS2.width+btnS2.height+10, 40);
           */
           
            
            
            _cbtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [_payWayBgView addSubview:_cbtn];
            [_cbtn setImage:IMAGE(@"pay_chose") forState:UIControlStateNormal];
            _cbtn.frame = CGRectMake(SCREEN_WIDTH-60, _line.y+1, 40, 40);
            
            
        }
        return ff;
    }
    return nil;
}

- (void)selectAliPayWay:(UIView *)sender
{
    NSLog(@"select pay way :%ld",sender.tag);
    if (sender.tag == 111) {
        _cbtn.frame =  CGRectMake(SCREEN_WIDTH-60, _line.y+1, 40, 40);
        _payment.tag = 201;
    }
}
- (void)selectWechatPayWay:(UIView *)sender
{
	NSLog(@"select pay way :%ld",sender.tag);
	
	if (sender.tag == 112) {
		_cbtn.frame = CGRectMake(SCREEN_WIDTH-60, _line2.y+1, 40, 40);
		_payment.tag = 202;
	}
}

#pragma mark ==========响应方法==========
- (void)paymentClick:(UIButton *)sender {
    NSLog(@"点击确认付款");
    //wx_app
    NSDictionary *param;
    NSLog(@"zhifu tag is %ld", sender.tag);
    if (sender.tag == 201) {
        param = @{@"channel":@"ali_app",
                  @"order_ids":self.orderNum};
        [[NetworkTool sharedTool] requestWithName:@"确认付款" URLString:APIMallsPayment parameters:param method:@"POST" callBack:^(id responseObject) {
            
            //        [self returnAction:nil];
            //        [self.navigationController popViewControllerAnimated:YES];
            
            NSString *orderString = responseObject[@"data"][@"param_str"];
            
            [AliPayServer aliPay:orderString memo:@"支付成功"];
        }];
    }
    else
    {
        param = @{@"channel":@"wx_app",
                  @"order_ids":self.orderNum};
        [[NetworkTool sharedTool] requestWithName:@"确认付款" URLString:APIMallsPayment parameters:param method:@"POST" callBack:^(id responseObject) {
            
            //        [self returnAction:nil];
            //        [self.navigationController popViewControllerAnimated:YES];
            
            [AliPayServer wxPay:responseObject[@"data"][@"param_obj"]];
        }];
    }
    
    
    
    
}
- (void)addressClick:(id)sender {
    NSLog(@"点击地址");
//    __weak MallCommitOrdersViewController *blockSelf = self;
    MallAddressViewController *addressVC = [[MallAddressViewController alloc] init];
    [addressVC returnAddress:^(NSDictionary *addr) {
        
        _shipAddress.text = addr[@"addr"];
        _shipAddrName.text = addr[@"name"];
        _shipAddrMobile.text = addr[@"mobile"];
        
        // 重新布局
        [self ownAddress];
        
        
    }];
    // 传多个订单id ， 同时修改地址
    addressVC.orderId = [self.orderData[0] valueForKey:@"order_id"];
    [self.navigationController pushViewController:addressVC animated:YES];
}


#pragma mark ===========pay==============
/*
- (void)returnAction:(UIButton *)sender {
 
    NSArray *array = self.navigationController.viewControllers;
    NSArray* reversedArray = [[array reverseObjectEnumerator] allObjects];
    for (UIViewController *controller in reversedArray) {
        if ([controller isKindOfClass:[MallDetailViewController class]]) {
            MallDetailViewController *vc =(MallDetailViewController *)controller;
            [self.navigationController popToViewController:vc animated:YES];
            return;
        }
        else if ([controller isKindOfClass:[MKJShoppingCartViewController class]]){
            MallHomeViewController *vc = (MallHomeViewController *)controller;
            [self.navigationController popToViewController:vc animated:YES];
            return;
        }
    }
}
 */


- (UIView *)createLineFrame:(CGRect)frame {
    UIView *line = [[UIView alloc] init];
    [self.view addSubview:line];
    line.backgroundColor = UISeparatedColorRGB;
    line.frame = frame;
    return line;
}

// 懒加载
- (NSMutableArray *)orderGoodArr {
    if (_orderGoodArr == nil) {
        _orderGoodArr = [[NSMutableArray alloc] initWithArray:self.orderData];
    }
    return _orderGoodArr;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
